package com.cswnode.demo.controller;

import com.cswnode.demo.controller.requestVariable.GetSexRatio;
import com.cswnode.demo.service.DataService;
import com.cswnode.demo.util.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author csw
 * @create 2021/3/22 23:08
 */
@Api(tags = "数据汇总")
@RequestMapping("/data")
@RestController
public class DataController {

    @Autowired
    private DataService dataService;

    @ApiOperation(value = "获得总数据汇总")
    @GetMapping("/getDataSummary")
    public ResponseVo getDataSummary() {
        return ResponseVo.success(dataService.getDataSummary());
    }

    @ApiOperation(value = "获得男女比例")
    @PostMapping("/getSexRatio")
    public ResponseVo getSexRatio(@RequestBody GetSexRatio getSexRatio) {
        return ResponseVo.success(dataService.getSexRation(getSexRatio));
    }

    @ApiOperation(value = "获得就业方向")
    @PostMapping("/getUnemployedRate")
    public ResponseVo getUnemployedRate(@RequestBody GetSexRatio getSexRatio) {
        return ResponseVo.success(dataService.getUnemployedRate(getSexRatio));
    }

    @ApiOperation(value = "获得薪资")
    @PostMapping("/getSalary")
    public ResponseVo getSalary(@RequestBody GetSexRatio getSexRatio) {
        List<Map<String, Integer>> salary = dataService.getSalary(getSexRatio);
        List<Object> Salaty = new ArrayList<>();
        List<String> nameList = new ArrayList<>();
        List<Object> valueList = new ArrayList<>();
        List<Object> maxList = new ArrayList<>();
        List<Object> minList = new ArrayList<>();
        for (Map<String, Integer> map : salary){
            String name = String.valueOf(map.get("name"));
            Object value = map.get("value");
            Object max = map.get("max");
            Object min = map.get("min");
            nameList.add(name);
            valueList.add(value);
            maxList.add(max);
            minList.add(min);
        }
        Salaty.add(nameList);
        Salaty.add(valueList);
        Salaty.add(maxList);
        Salaty.add(minList);
        return ResponseVo.success(Salaty);
    }

    @ApiOperation(value = "获得工作地点")
    @PostMapping("/getWorkMap")
    public ResponseVo getWorkMap(@RequestBody GetSexRatio getSexRatio) {
        List<Map<String, String>> workAddress = dataService.getWorkAddress(getSexRatio);
        for (Map<String, String> map : workAddress){
            String name = map.get("name");
            if (StringUtils.isEmpty(name)){
                continue;
            }
            if (name.equals("黑龙江")){
                map.put("name","黑龙江");
                continue;
            }
            if (name.equals("内蒙古")){
                map.put("name","内蒙古");
                continue;
            }
            map.put("name",name.substring(0,2));
        }
        return ResponseVo.success(workAddress);
    }




}
